package {
	import com.tenoz.display.DropdownMenu;
	import com.tenoz.display.MenuItem;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class MenuTest extends Sprite
	{
		public var test:DropdownMenu;
		public var xml:XML;
		
		public function MenuTest()
		{
			xml = <menu>
					<name>Print</name>
					<items>
						<item>
							<name>Printer-friendly map</name>
							<id>001</id>
							<type>LINK</type>
						</item>
						<item>
							<name>Driving directions</name>
							<id>002</id>
							<type>LINK</type>
						</item>
						<item>
							<name>Show on Google Maps</name>
							<id>003</id>
							<type>LINK</type>
						</item>
						<item>
							<name>Email this map to a Friend</name>
							<id>004</id>
							<type>LINK</type>
						</item>
						<item>
							<name>Printer-friendly map</name>
							<id>001</id>
							<type>LINK</type>
						</item>
						<item>
							<name>Driving directions</name>
							<id>002</id>
							<type>LINK</type>
						</item>
						<item>
							<name>Show on Google Maps</name>
							<id>003</id>
							<type>LINK</type>
						</item>
						<item>
							<name>Email this map to a Friend</name>
							<id>004</id>
							<type>LINK</type>
						</item>
					</items>
				</menu>;
				
			test.init(xml);
			test.onResize(stage.stageWidth, stage.stageHeight);
			test.addEventListener(MouseEvent.MOUSE_OVER, onOver);
			test.addEventListener(MouseEvent.MOUSE_OUT, onOut);
			stage.addEventListener(MouseEvent.CLICK, onClick);
//			test.addEventListener(MouseEvent.MOUSE_OUT, closeMenu);
		}
		
//		public function closeMenu(e:MouseEvent):void
//		{
//			test.closeMenu();
//		}
		
		public function onOver(e:MouseEvent):void
		{
			test.openMenu();
		}
		public function onOut(e:MouseEvent):void
		{
			test.closeMenu();
		}
		
		public function onClick(e:MouseEvent):void
		{
			if(e.target is MenuItem)
			{
				var item:MenuItem = MenuItem(e.target);
				trace(item);
				test.closeMenu();
			}
		}
	}
}
